package com.common.util;

import org.apache.commons.lang3.StringUtils;

public class ParamUtil {

    public static String getClassName(String name) {
        String[] names = name.split("_");
        StringBuilder builder = new StringBuilder();
        for (String str : names) {
            builder.append(indexUpper(str, true));
        }
        return builder.toString();
    }

    public static String getClassFiledName(String name) {
        String[] names = name.split("_");
        StringBuilder builder = new StringBuilder();
        boolean isFist = false;
        for (String str : names) {
            if (StringUtils.isBlank(str)) {
                continue;
            }
            builder.append(indexUpper(str, isFist));
            isFist = true;
        }
        return builder.toString();
    }

    public static String getClassMethdodName(String name) {
        String[] names = name.split("_");
        StringBuilder builder = new StringBuilder();
        for (String str : names) {
            builder.append(indexUpper(str, true));
        }
        return builder.toString();
    }

    private static String indexUpper(String name, boolean fistUpper) {
        String pre = name.substring(0, 1);
        String nex = name.substring(1);
        if (fistUpper) {
            return StringUtils.upperCase(pre) + nex;
        }
        return StringUtils.lowerCase(pre) + nex;
    }
}
